//package com.videoaggre.zcl.ui.activity.agefans
//
//import android.content.Context
//import android.text.method.LinkMovementMethod
//import android.text.style.ClickableSpan
//import android.view.View
//import android.view.ViewGroup
//import androidx.core.app.ComponentActivity
//import androidx.recyclerview.widget.DefaultItemAnimator
//import com.kingja.loadsir.core.LoadService
//import com.videoaggre.zcl.R
//import com.videoaggre.zcl.bean.AgefansDetails
//import com.videoaggre.zcl.bean.AgefansDetailsSerie
//import com.videoaggre.zcl.bean.AgefansDetailsTag
//import com.videoaggre.zcl.common.*
//import com.videoaggre.zcl.databinding.AgefansItemDescBinding
//import com.videoaggre.zcl.databinding.AgefansItemSerieBinding
//import com.videoaggre.zcl.helper.InjectBundle
//import com.videoaggre.zcl.helper.OnTabSelectedListener
//import com.videoaggre.zcl.helper.loadsir.LoadSirHelper
//import com.videoaggre.zcl.helper.newInstance
//import com.videoaggre.zcl.parse.BaseParse
//import com.videoaggre.zcl.parse.impl.AgefansParse
//import com.videoaggre.zcl.ui.activity.BaseActivity
//import com.videoaggre.zcl.ui.adapter.AgefansItemAdapter
//import com.videoaggre.zcl.ui.adapter.BaseRecyclerAdapter
//import com.videoaggre.zcl.ui.adapter.BaseSignCheckAdapter
//import com.videoaggre.zcl.ui.adapter.BaseViewHolder
//import com.videoaggre.zcl.ui.fragment.parseHtml
//import com.videoaggre.zcl.ui.widget.CommonButton
//import com.videoaggre.zcl.utils.FullyGridLayoutManager
//import com.videoaggre.zcl.utils.FullyLinearLayoutManager
//import com.videoaggre.zcl.utils.GlideUtils
//import kotlinx.android.synthetic.main.activity_agefans_details.*
//import java.lang.StringBuilder
//class AgefansDetailsActivity : BaseActivity(R.layout.activity_agefans_details) {
//    companion object {
//        private const val DETAILS_LINK = "mDetailsLink"
//        fun open(context: Context, link: String) = context.startKtxActivity<AgefansDetailsActivity>(value = DETAILS_LINK to link)
//    }
//
//    private val mLoadService: LoadService<*> by lazy { LoadSirHelper.register(rootView) { onReload() } }
//    private val mAgefansDetailsDescAdapter: AgefansDetailsDescAdapter by newInstance()
//    private val mAgefansDetailsSerieAdapter: AgefansDetailsSerieAdapter by newInstance()
//    private val mRecommendedAdapter: AgefansItemAdapter by newInstance()
//    private val mDetailsLink: String by InjectBundle()
//    private lateinit var mAgefansDetails: AgefansDetails
//    override fun initView() {
//        rvDesc.layoutManager = FullyLinearLayoutManager(this)
//        rvDesc.adapter = mAgefansDetailsDescAdapter
//        rvSeries.layoutManager = FullyGridLayoutManager(this, 3)
//        rvSeries.adapter = mAgefansDetailsSerieAdapter
//        mAgefansDetailsSerieAdapter.activity = this
//        (rvSeries.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
//        rvRecommend.layoutManager = FullyGridLayoutManager(this, 3)
//        rvRecommend.adapter = mRecommendedAdapter
//    }
//
//    override fun initData() {
//        mLoadService.showLoadingCallback()
//        onReload()
//    }
//
//    private fun onReload() {
//        parseHtml(BaseParse(this, this, mDetailsLink, loadService = mLoadService) {
//            AgefansParse.parseDetails(it) {
//                runOnUiThread {
//                    mAgefansDetails = it
//                    titleView.titleStr = it.name
//                    GlideUtils.intoView(this, it.cover, ivCover)
//                    mAgefansDetailsDescAdapter.datas = it.tags
//                    mAgefansDetailsDescAdapter.notifyDataSetChanged()
//                    groupRelates.changeVisibility = it.relatesSeries.isNotEmpty()
//                    if (it.relatesSeries.isNotEmpty()) {
//                        tvRelates.movementMethod = LinkMovementMethod.getInstance();
//                        val relatesSeriesText = StringBuilder()
//                        tvRelates.textSpan("textSpan") {
//                            it.relatesSeries.forEach { agefansItem ->
//                                relatesSeriesText.append(agefansItem.name).append("\n")
//                                spanText = agefansItem.name
//                                addUnderlineSpan()
//                                addClickableSpan(object : ClickableSpan() {
//                                    override fun onClick(widget: View) = open(widget.context, agefansItem.link)
//                                })
//                            }
//                            relatesSeriesText.deleteCharAt(relatesSeriesText.length - 1)
//                            text = relatesSeriesText.toString()
//                        }
//                    }
//                    tvIntro.changeText(it.intro)
//                    if (it.series.isNotEmpty()) {
//                        tlSeries.tabData {
//                            for (i in 1..it.series.size) {
//                                tab(getString(R.string.agefans_text_play_list, i))
//                            }
//                        }
//                        tlSeries.addOnTabSelectedListener(OnTabSelectedListener { changeSerie(mAgefansDetails.series[it.position]) })
//                        changeSerie(it.series[0])
//                    }
//                    mRecommendedAdapter.datas = it.recommends
//                    mRecommendedAdapter.notifyDataSetChanged()
//                }
//            }
//        })
//    }
//
//    private fun changeSerie(series: MutableList<AgefansDetailsSerie>) {
//        mAgefansDetailsSerieAdapter.datas = series
//        mAgefansDetailsSerieAdapter.notifyDataSetChanged()
//    }
//
//
//}
//
//class AgefansDetailsSerieAdapter : BaseSignCheckAdapter<BaseViewHolder<AgefansItemSerieBinding>, AgefansDetailsSerie>() {
//    var activity: ComponentActivity? = null
//    override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = BaseViewHolder(AgefansItemSerieBinding.inflate(getLayoutInflate(parent.context), parent, false))
//    override fun onBindViewHolder(holder: BaseViewHolder<AgefansItemSerieBinding>, bean: AgefansDetailsSerie, position: Int) {
//        holder.mViewBinding.run {
//            bean.run {
//                cbSerie.text = name
//                cbSerie.changeStyle(if (check) CommonButton.CB_STROKE_NORMAL else CommonButton.CB_STROKE_TEXT)
//                setViewClick(position, cbSerie)
//            }
//        }
//    }
//
//    override fun subOnClickAdapter(v: View, position: Int) {
//        super.subOnClickAdapter(v, position)
//        activity?.let { AgefansVideoPlayerActivity.open(it, getItem(position).link) }
//        /*activity?.let { activity ->
//            val mAgefansDetailsSerie = getItem(position)
//            Logger.e(mAgefansDetailsSerie.link)
//            parseHtml(object : BaseParse(activity, activity, mAgefansDetailsSerie.link, successParse = {
//                AgefansParse.parseSerie(it) {
//                    Logger.e("parseSerie==>${it}")
////                    activity.lifecycleScope.launch {
////                        parseHtml(object : BaseParse(activity, activity, it, successParse = {
////                            AgefansParse.parseSerieLink(it) {
////                                Logger.e("最终地址==>${it}")
////                                TbsVideo.openVideo(activity, it.let { if (!it.startsWith("http")) "http:$it" else it })
////                            }
////                        }) {
////                            override fun onPageFinished(webView: WebView, url: String) {
////                                webView.evaluateJavascript("""javascript:setTimeout(function () {Jsbridge.html(document.getElementsByTagName('html')[0].innerHTML)},1000)""") {}
////                            }
////                        })
////                    }
//                    *//*activity.runOnUiThread {
//                        activity.startActivity(Intent().apply {
//                            action = Intent.ACTION_VIEW
//                            data = Uri.parse(it)
//                        })
//                    }*//*
//                }
//            }) {
//                override fun onPageFinished(webView: WebView, url: String) {
//                    webView.evaluateJavascript("""javascript:setTimeout(function () {Jsbridge.html(document.getElementsByTagName('html')[0].innerHTML)},2000)""") {}
//                }
//            })
//        }*/
//    }
//}
//
//class AgefansDetailsDescAdapter : BaseRecyclerAdapter<BaseViewHolder<AgefansItemDescBinding>, AgefansDetailsTag>() {
//    override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = BaseViewHolder(AgefansItemDescBinding.inflate(getLayoutInflate(parent.context), parent, false))
//    override fun onBindViewHolder(holder: BaseViewHolder<AgefansItemDescBinding>, bean: AgefansDetailsTag, position: Int) {
//        holder.mViewBinding.run {
//            bean.run {
//                tvDescName.text = tagName
//                tvDescValue.text = tagValue
//                setViewClick(position, root)
//            }
//        }
//    }
//}
